package sort;

import java.util.Arrays;

public class SelectionSort {
    public static void main(String[] args) {
        s1();
        s2();
    }

    private static void s1() {
        int[] arr = {1, 5, 3, 7, 9, 2, 4, 6, 8};
        for (int i = 0; i < arr.length - 1; i++) {
            int index = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] > arr[index]) index = j;
            }
            if (index != i) {
                arr[i] = arr[i] ^ arr[index];
                arr[index] = arr[i] ^ arr[index];
                arr[i] = arr[i] ^ arr[index];
            }
        }
        System.out.println(Arrays.toString(arr));
    }

    private static void s2() {
        int[] arr = {1, 5, 3, 7, 9, 2, 4, 6, 8};
        for (int i = 0; i < arr.length - 1; i++) {
            int index = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[index])
                    index = j;
            }
            if (index != i) {
                arr[i] = arr[i] ^ arr[index];
                arr[index] = arr[i] ^ arr[index];
                arr[i] = arr[i] ^ arr[index];
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
